//package com.situ.skymall.admin.api.common;
//
//import com.alibaba.fastjson2.JSON;
//import com.auth0.jwt.JWT;
//import com.auth0.jwt.JWTVerifier;
//import com.auth0.jwt.algorithms.Algorithm;
//import com.auth0.jwt.exceptions.JWTVerificationException;
//import com.auth0.jwt.interfaces.DecodedJWT;
//import com.situ.utils.JsonResult;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.http.HttpStatus;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import java.io.PrintWriter;
//
//@Component
//public class JwtInterceptor implements HandlerInterceptor {
//    @Value("${jwt.secret}")
//    private String jwtSecret;
//    public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
//        String jwt = req.getHeader("Authorization");
//        if(!StringUtils.hasText(jwt)){
//            jwt= req.getParameter("Authorization");
//        }
//        //验证token
//        JWTVerifier verifier = JWT.require(Algorithm.HMAC256(jwtSecret)).build();
//        try {
//            DecodedJWT dj = verifier.verify(jwt);
//            return true;
//        } catch (JWTVerificationException e) {
//            String msg = "jwt验证失败";
//            resp.setStatus(HttpStatus.UNAUTHORIZED.value());
//            resp.setContentType("application/json;charset=utf-8");
//            PrintWriter out = resp.getWriter();
//            out.write(JSON.toJSONString(JsonResult.fail(401,msg)));
//            out.flush();
//            return false;
//        }
//
//    }
//}
